file = open("matrix.txt", "r")
array = [[int(x) for x in line.split(",")] for line in file]

#array = [[131, 673, 234, 103, 18],
#         [201, 96, 342, 965, 150],
#         [630, 803, 746, 422, 111],
#         [537, 699, 497, 121, 956],
#         [805, 732, 524, 37, 331]]
rows = len(array)
columns = len(array[0])

minsums = [[0 for c in xrange(columns)] for r in xrange(rows)]
minsums[0][0] = array[0][0]

for row in xrange(1, rows):
    minsums[row][0] = minsums[row-1][0] + array[row][0]

for column in xrange(1, columns):
    minsums[0][column] = minsums[0][column-1] + array[0][column]

for row in xrange(1, rows):
    for column in xrange(1, columns):
        minsums[row][column] = min(minsums[row-1][column], minsums[row][column-1]) + array[row][column]
        
print minsums[rows - 1][columns - 1]